<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>评价展示</title>
    <link rel="stylesheet" href="/js/bootstrap.min.css">
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var comment = $("#comment");
            var pageNo = 1;
            var total = null;
            var ids = null;//ID


            //设置首页
            $("#first").click(function () {
                pageNo = 1;
                load();
            });

            //设置上一页
            $("#prev").click(function () {
                if (pageNo <= 1)
                    return;
                pageNo--;
                load();
            });

            //设置下一页
            $("#next").click(function () {
                if (pageNo >= total)
                    return;
                pageNo++;
                load();
            });

            //设置尾页
            $("#last").click(function () {
                pageNo = total;
                load();
            });

            var level = null;//等级
            var minModifydate = null;
            var maxModifydate = null;
            //点击事件
            $("#button").click(function () {
                level = $("input[type='radio']:checked").val() == null ? "" : $("input[type='radio']:checked").val();
                pageNo = 1;
                minModifydate = $("#minModifydate").val();
                maxModifydate = $("#maxModifydate").val();
                load();
                return false;
            });

            function load() {
                comment.find("tr:gt(0)").remove();
                $.get("/applets/comment/page", {
                    "pageNo": pageNo,
                    "pageSize": 5,
                    "level": level,
                    "minModifydate": minModifydate,
                    "maxModifydate": maxModifydate
                }, function (da) {
                    if (da.code != 0) {
                        alert(da.msg);
                        return;
                    }
                    var map = da.data;
                    total = map.total;
                    $.each(map.list, function (i, d) {
                        comment.append("<tr><td>" + d.id + "</td><td>" + d.userid +
                            "</td><td>" + d.modifydate + "</td><td>" + d.level +
                            "</td><td>" + d.imgs + "</td><td>" + d.orderid +
                            "</td><td>" + getRsu(d.isdel) + "</td><td>" + d.conent +
                            "</td><td><button type='button' class='btn btn-primary btn-sm' id='del' code='" + d.id +
                            "'>删除</button>&nbsp;<a class='btn btn-primary btn-sm'  href='/applets/comment/additional?id=" + d.id +
                            "'>追加</a></td></tr>"
                        )
                    })
                });
            };

            //点击删除事件
            comment.on("click", '#del', function () {
                ids = $(this).attr("code");
                del();
                return false;
            });

            //删除商品的ajax
            function del() {
                var a = confirm("是否删除该评价?");
                if (!a)
                    return;
                $.ajax({
                    url: "/applets/comment/delete",
                    data: {"id": ids},
                    type: "post",
                    success: function (ur) {
                        alert(ur.msg);
                    }
                });
            };

            //状态
            function getRsu(q) {
                if (q == true) {
                    return "是";
                }
                return "否";
            }

            load();

        });
    </script>
</head>
<body>
<div class="container">
    <h2 class="text-center">商品种类表</h2>

    <!--导航-->
    <ul class="nav nav-tabs">
        <li class="nav-item">
            <a class="nav-link active" href="/Menu.html">返回主菜单</a>
        </li>
    </ul>

    <!--表单-->
    <form action="#" method="get">
        <div class="form-group">
            <label>初始时间: <input type="date" id="minModifydate" class="form-control" name="modifydate"></label>
            <label>结束时间: <input type="date" id="maxModifydate" class="form-control" name="modifydate"></label>
        </div>
        <div class="form-group">
            <label>评价等级</label>
            <label class="radio-inline"><input type="radio" name="level" value="1">一星</label>
            <label class="radio-inline"><input type="radio" name="level" value="2">二星</label>
            <label class="radio-inline"><input type="radio" name="level" value="3">三星</label>
            <label class="radio-inline"><input type="radio" name="level" value="4">四星</label>
            <label class="radio-inline"><input type="radio" name="level" value="5">五星</label>
        </div>
        <div class="form-group">
            <input type="button" id="button" class="form-control" value="查找评价">
        </div>
    </form>
</div>
<div class="container">
    <table id="comment" class="table table-striped">
        <thead>
        <tr>
            <th>ID</th>
            <th>评论人</th>
            <th>评论时间</th>
            <th>评价等级</th>
            <th>图片</th>
            <th>订单号</th>
            <th>是否存在</th>
            <th>评论内容</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

<div class="container offset-md-5">
    <ul class="pagination">
        <li class="page-item" id="first"><a class="page-link">首页</a></li>
        <li class="page-item" id="prev"><a class="page-link">上一页</a></li>
        <li class="page-item" id="next"><a class="page-link">下一页</a></li>
        <li class="page-item" id="last"><a class="page-link">尾页</a></li>
    </ul>
</div>

</body>
</html>